<template >
  <div class="home-recommend">
    <h1>达人歌单</h1>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li v-for="(item, index) in listData" :key="index" @click="selectItem(item)">
          <div class="cover">
            <van-image :src="item.cover" />
            <span>{{ item.listen_num|numFilter }}</span>
          </div>
          <span>{{ item.title }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import router from '@/router/index.js';
// import BScroll from "better-scroll";
import {betterScrollHorizontal} from "../../common/betterScroll.js"
export default {
  data() {
    return { listData: [] };
  },
  created() {
    this.getSongListData();
  },

  methods: {
    getSongListData() {
      this.$request("get", "/recommend/playlist/u").then((res) => {
        console.log(res);
        if (res.result == 100) {
          this.listData = res.data.list;
        }
        // this.betterScrollHorizontal(this.listData.length, 10);
        betterScrollHorizontal(this,this.$refs.wrapper,this.$refs.content,this.listData.length, 10)
      });
    },
    selectItem(item){
      const id=item.content_id;
      router.push({name:"songlist",params:{id:id}})
    }
    // //横向滚动方法封装
    // betterScrollHorizontal(num, itemWidth) {
    //   // 计算内容区的宽度
    //   this.$refs.content.style.width = num * itemWidth + "rem";
    //   this.$nextTick(() => {
    //     this.scroll = new BScroll(this.$refs.wrapper, {
    //       scrollX: true,
    //       scrollY: false,
    //       startX: 0,
    //     });
    //   });
    // },
  }
};
</script>

<style scoped>
/* .home-recommend  ul {
  display: flex;
  flex-wrap: wrap;
}
.home-recommend  ul > li {
  width: calc((100% - 1rem) / 3 * 1);
}
.home-recommend ul > li:nth-of-type(3n + 2) {
  margin-left: 0.5rem;
  margin-right: 0.5rem;
}*/

.wrapper {
  width: 100vw;
  overflow: hidden;
}
/* ul.content {
  width: calc(12 * 10.2rem);
} */
ul.content li {
  width: 10rem;
  display: inline-block;
  vertical-align: top;
  margin: 0 0 0.1rem;
}
ul.content li * {
  margin: 0 0.1rem;
}
ul.content li > span {
  font-size: 0.8rem;
  color: red;
}
.cover {
  position: relative;
}
.cover > span {
  position: absolute;
  right: 0;
  bottom: 0.4rem;
  background-color: #a6a0a0;
  color:white;
  border-radius: 1rem;
  width: 5rem;
}
</style>